package sunstar.com.xq.activity

import android.graphics.Bitmap
import android.graphics.Typeface
import android.graphics.drawable.Drawable
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.design.R.id.text
import android.support.v7.graphics.Palette
import com.squareup.picasso.Picasso
import com.squareup.picasso.Target
import kotlinx.android.synthetic.main.activity_single_image_info.*
import sunstar.com.xq.R
import sunstar.com.xq.databean.CardData
import java.lang.Exception

class SingleImageInfoActivity : BaseActivity() {
    override fun setBaseView(): Int =R.layout.activity_single_image_info

    override fun setTitleText(): String = ""

    override fun showTitle(): Boolean = false

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setView()
    }

    private fun setView() {
        var data = intent.getSerializableExtra("data") as CardData

        single_text.text = data.cardInfo
        single_img_toolbar_layout.title = data.cardTtitle
        single_img_toolbar_layout.setContentScrimColor(resources.getColor(R.color.colorPrimary))
        Picasso.with(this@SingleImageInfoActivity).load(data.cardImg)!!.into(object : Target {

            override fun onPrepareLoad(placeHolderDrawable: Drawable?) {

            }

            override fun onBitmapFailed(errorDrawable: Drawable?) {
            }

            override fun onBitmapLoaded(bitmap: Bitmap?, from: Picasso.LoadedFrom?) {
                single_img.setImageBitmap(bitmap)
                var bulid = Palette.from(bitmap)
                var palette = bulid.generate()
                var s1 = palette.mutedSwatch
                var s2 = palette.lightVibrantSwatch
                var s3 = palette.vibrantSwatch
                try {
                    activity_single_image_info.setBackgroundColor(s1!!.rgb)
                    single_appbar_layout.setBackgroundColor(s2!!.rgb)
                    single_img_toolbar_layout.setContentScrimColor(s2!!.rgb)
                    single_img_toolbar_layout.setExpandedTitleColor(s2.titleTextColor)
                    single_img_toolbar_layout.setCollapsedTitleTextColor(s3!!.titleTextColor)
                    single_text.setTextColor(s3!!.bodyTextColor)
                } catch (e: Exception) {

                }
            }
        })
    }
}
